<extend name="Base/common"/>
<block name="css">

</block>
<block name="body">
    <header class="mui-bar mui-bar-nav dl_header">
        <a href="javascript:history.back();" id="close" class="iconfont icon-guanbi dl_closed"></a>
        <a href="javacript:" class="dl_fast" id="action">操作</a>
    </header>
    <div class="mui-content" id="container_wrap">
        <div  style="display: -webkit-box;-webkit-box-orient: horizontal;-webkit-box-pack: center;overflow: hidden;">
            <img src="__PUBLIC__/Home/images/index/xglogo.png" class="img-responsive center-block logo"/>
        </div>
        <!--账号密码登录-->
        <table class="table " >
            <thead>
            <tr>
                <th>编号</th>
                <th width="">姓名</th>
                <th width="">首次提交时间</th>
                <th width="">是否缴费</th>
                <th width="">凭证上传时间</th>
                <th width="">操作</th>
            </tr>
            </thead>
            <tbody>
            <volist name="info" id="vo">
                <tr>
                    <td>{$vo.id}</td>
                    <td>{$vo.name}</td>
                    <td>{$vo.create_time|time_format}</td>
                    <td><empty name="vo['pay_evidence']">未交费<else />已缴费</empty></td>
                    <td><if condition="$vo['upload_time'] gt 0">{$vo.upload_time|time_format}<else />还未上传</if></td>
                    <td>
                        <empty  name="vo['pay_evidence']">
                            <a href="{:U('editSudentInfo',array('id'=>$vo['id']))}">编辑</a>
                          <else />
                            <a href="{:U('showStudentInfo',array('id'=>$vo['id']))}">查看</a>
                        </empty >
                    </td>
                </tr>
            </volist>
            </tbody>
        </table>

    </div>

    <div id="action_select">
        <div class="acc_phone_div1" style="height:15%;">
            <ul style="line-height: 25px;">
                <li class="per_headimg">
                  <a href="{:U('Agent/index')}">添加信息</a>
                </li>

                <li class="per_headimg">
                    <a href="{:U('Wap/Home/exportExcel')}">导出表格</a>
                </li>
            </ul>
        </div>
        <div class="acc_phone_qux">取消</div>
    </div>
</block>

<block name="script">
    <script>
        $("#action").click(function(){
            $('#action_select').css("display","block");
            $(".acc_phone_qux").click(function(){
                $("#action_select").css("display","none");
            });
            $('.per_headimg').click(function(){
                $("#head_image").css("display","none");
            })
        });

        $('.myfile').change(function(event) {
            // 根据这个 <input> 获取文件的 HTML5 js 对象
            var files = event.target.files,file = files[0];;
            // 获取目前上传的文件
            var imgarr = ['image/png','image/jpg','image/jpeg','image/gif'];//图片格式
            // 实例化一个表单数据对象
            var formData = new FormData();
            if(file.size > 1024 * 1024 * 2) {
                $.dialog({
                    content : '图片大小不能超过 2MB!',
                    title: "alert",
                    time : 1000
                });
                $('.myfile').val('');
                return false;
            }
            //区分文件类型  inArray()函数
            if($.inArray (file.type,imgarr) != -1){
                formData.append('download',file);
            }else {
                $.dialog({
                    content : '只能上传图片',
                    title: "alert",
                    time : 1000
                });
                $('.myfile').val('');
                return false;
            }
            $.ajax({
                url: "{:U('Home/File/upload')}",
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    //提示上传失败的原因
                    if(result.status==1)
                    {
                        $.dialog({
                            content : "上传成功",
                            title: "ok",
                            time : 1000
                        });
                        $("#pay_evidence").val(result.url);
                        $("#pay_evidence_img").attr('src',result.url);
                        return false;
                    }else{
                        $.dialog({
                            content : "上传失败",
                            title: "alert",
                            time : 1000
                        });
                    }
                },
                error: function (result) {
                    $.dialog({
                        content : "上传失败",
                        title: "alert",
                        time : 1000
                    });
                }
            });
        });

        $("#add_btn").click(function(){
            var submit = true;
            var  $name=$("input[name=name]").val(),
                 $ID_number=$("input[name=ID_number]").val(),
                 $introducer=$("input[name=introducer]").val(),
                 $introducer_phone=$("input[name=introducer_phone]").val(),
                 $id=$("input[name=id]").val();

            if($name==''){
                $.dialog({
                    content : '请填写学生名字',
                    title: "alert",
                    time : 1000
                });
                return false;
            }

            if($ID_number==''){
                $.dialog({
                    content : '请填写身份证号',
                    title: "alert",
                    time : 1000
                });
                return false;
            }
            if($ID_number!=''){
                var reg = /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;
                if(reg.test($ID_number)){
                    if($id==''){
                        $.post('{:U("Agent/checkfield")}', {ID_number:$ID_number}, function(data){
                            if(data.status){
                                $.dialog({
                                    content : data.info,
                                    title: "alert",
                                    time : 1000
                                });
                                submit=false;
                            }
                        });
                    }
                }else{
                    $.dialog({
                        content : '身份证号格式正确',
                        title: "alert",
                        time : 1000
                    });
                    return false;
                }

            }

            if($introducer==''){
                $.dialog({
                    content : '请填写介绍人名字',
                    title: "alert",
                    time : 1000
                });
                return false;
            }

            if($introducer_phone==''){
                $.dialog({
                    content : '请填写介绍人电话',
                    title: "alert",
                    time : 1000
                });
                return false;
            }


            if(submit){
                $.post('{:U("Agent/saveSudentInfo")}', $("form").serialize(), function(data){
                    if(data.status){
                        $.dialog({
                            content : data.info,
                            title: "ok",
                            time : 1000
                        });
                        setTimeout(function () {
                            location.reload();
                        },1000);
                    }else{
                        $.dialog({
                            content : data.info,
                            title: "alert",
                            time : 1000
                        });
                    }
                });
            }

        });
    </script>
</block>